/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import java.util.List;

import com.comac.ins.isfd.domain.bo.IsfdDatasourceTemplateConditionBo;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceTemplateQueryBo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceTemplateBo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceTemplateVo;
import com.comac.ins.isfd.service.IIsfdDatasourceTemplateService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;

/**
 * 数据源数据集成-模版
 *
 * @author Lion Li
 * @date 2024-10-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/datasourceTemplate")
public class IsfdDatasourceTemplateController extends BaseController {

    private final IIsfdDatasourceTemplateService isfdDatasourceTemplateService;

    /**
     * 查询数据源数据模版列表
     */
    @SaCheckPermission("isfd:datasourceTemplate:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdDatasourceTemplateVo> list(@RequestBody IsfdDatasourceTemplateQueryBo isfdDatasourceTemplateQueryBo) {
        return isfdDatasourceTemplateService.queryPageList(isfdDatasourceTemplateQueryBo);
    }

    /**
     * 导出数据源数据模版列表
     */
    @SaCheckPermission("isfd:datasourceTemplate:export")
    @Log(title = "数据源数据模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody IsfdDatasourceTemplateQueryBo bo,HttpServletResponse response) {
        isfdDatasourceTemplateService.exportExcelById(bo,response);
    }


    /**
     * 获取数据源数据模版详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:datasourceTemplate:query")
    @GetMapping("/{id}")
    public R<IsfdDatasourceTemplateVo> getInfo(@NotNull(message = "主键不能为空")
                                               @PathVariable Long id) {
        return R.ok(isfdDatasourceTemplateService.queryById(id));
    }

    /**
     * 新增数据源数据模版
     */
    @SaCheckPermission("isfd:datasourceTemplate:add")
    @Log(title = "数据源数据模版", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdDatasourceTemplateBo bo) {
        return toAjax(isfdDatasourceTemplateService.insertByBo(bo));
    }

    /**
     * 修改数据源数据模版
     */
    @SaCheckPermission("isfd:datasourceTemplate:edit")
    @Log(title = "数据源数据模版", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/update")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdDatasourceTemplateBo bo) {
        return toAjax(isfdDatasourceTemplateService.updateByBo(bo));
    }

    /**
     * 删除数据源数据模版
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:datasourceTemplate:remove")
    @Log(title = "数据源数据模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdDatasourceTemplateService.deleteWithValidByIds(List.of(ids), true));
    }
    /**
     * 条件查询数据源数据模版列表
     */
    @SaCheckPermission("isfd:datasourceTemplate:list")
    @PostMapping("/queryTemplateByCondition")
    public TableDataInfo<IsfdDatasourceTemplateVo> queryTemplateByCondition(@RequestBody IsfdDatasourceTemplateConditionBo isfdDatasourceTemplateConditionBo) {
        return isfdDatasourceTemplateService.queryTemplateByCondition(isfdDatasourceTemplateConditionBo);
    }
}
